using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

using GonzalesCore.CoreElements;

using Kypris2.Utils;
using Kypris2.CoreElements;
using Kypris2.CoreManagers;

using Jamila2.CoreElements;
using Jamila2.Database;
using Jamila2.Tools;

namespace GonzalesCore.CoreManagers
{
    public abstract class DataOutputManagerBase : KyprisManagerBase, IManager, IDisposable
    {
        protected PersonalSessionAccount CurrentModuleSession = null;
        protected LogManager CurrentLogManager = null;                
        
        public FileDataColumnCollection DataColumns = new FileDataColumnCollection();

        public DataOutputManagerBase(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.CurrentModuleSession = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);
        }

        public abstract ArrayList GenerateFileContent(string Entity);

        #region FileDataColumnBase

        public class FileDataColumn
        {
            public int ColumnIndex = 0;
            public int Size = 0;
            public string Name = "";
            public string ActualName = "";
            public bool FromBack = false;

            public FileDataColumn(int index, int size, string name)
            {
                this.ColumnIndex = index;
                this.Size = size;
                this.Name = name;
            }

            public FileDataColumn(int index, int size, string name, string actual, bool back)
            {
                this.ColumnIndex = index;
                this.Size = size;
                this.Name = name;
                this.ActualName = actual;
                this.FromBack = back;
            }
        }

        public class FileDataColumnCollection : CollectionBase
        {

            public FileDataColumn this[int index]
            {
                get
                {
                    return ((FileDataColumn)List[index]);
                }
                set
                {
                    List[index] = value;
                }
            }

            public int Add(FileDataColumn value)
            {
                return (List.Add(value));
            }

            public int IndexOf(FileDataColumn value)
            {
                return (List.IndexOf(value));
            }

            public void Insert(int index, FileDataColumn value)
            {
                List.Insert(index, value);
            }

            public void Remove(FileDataColumn value)
            {
                List.Remove(value);
            }

            public bool Contains(FileDataColumn value)
            {
                // If value is not of type Int16, this will return false.
                return (List.Contains(value));
            }
        }


        #endregion
    }

    #region ClaimTransactionDataOutputManager
    public class ClaimTransactionDataOutputManager : DataOutputManagerBase
    {
        public ClaimTransactionDataOutputManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {            

            // defined data column
            this.DataColumns.Add(new FileDataColumn(0, 10, "ECLAIM", "ECLAIM", true));
            this.DataColumns.Add(new FileDataColumn(1, 9, "EINVDT", "EINVDT", false));
            this.DataColumns.Add(new FileDataColumn(2, 1, "EPAYTY", "EPAYTY", true));
            this.DataColumns.Add(new FileDataColumn(3, 10, "EACC", "EACC", true));
            this.DataColumns.Add(new FileDataColumn(4, 6, "EEMPID", "EEMPID", true));
            this.DataColumns.Add(new FileDataColumn(5, 2, "ENTITY", "ENTITY", true));
            this.DataColumns.Add(new FileDataColumn(6, 3, "ECOMP", "ECOMP", false));
            this.DataColumns.Add(new FileDataColumn(7, 17, "ELAMT", "ELAMT", false));
            this.DataColumns.Add(new FileDataColumn(8, 17, "ELTAX", "ELTAX", false));
            this.DataColumns.Add(new FileDataColumn(9, 10, "EPRJID", "EPRJID", true));
            this.DataColumns.Add(new FileDataColumn(10, 10, "EPC", "EPC", true));
            this.DataColumns.Add(new FileDataColumn(11, 6, "EEMPCH", "EEMPCH", true));
            //this.DataColumns.Add(new FileDataColumn("EDESC", Type.GetType("System.String")));
            this.DataColumns.Add(new FileDataColumn(12, 40, "EDESC", "EDESC", true));
        }        

        #region GenerateFileContent
        public override ArrayList GenerateFileContent(string Company)
        {
            ArrayList ResultList = null;
            int counter = 0;
            int temp = 0;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter("@CompanyID", Company));

                this.CurSQLFactory.ExecuteStoredProcedure("sp_FILEOUT_Transaction", KeyParameters);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    // generate file now
                    ResultList = new ArrayList();

                    try
                    {
                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                            string[] ResultArray = new string[this.DataColumns.Count];

                            DateTime CurDate = DateTime.Parse(ResultRow[this.DataColumns[1].ActualName].ToString());

                            ResultArray[this.DataColumns[0].ColumnIndex] = ResultRow[this.DataColumns[0].ActualName].ToString();
                            ResultArray[this.DataColumns[1].ColumnIndex] = CurDate.Year + SwissArmy.StringAppend(CurDate.Month, "0", 2, false) + SwissArmy.StringAppend(CurDate.Day, "0", 2, false);
                            ResultArray[this.DataColumns[2].ColumnIndex] = ResultRow[this.DataColumns[2].ActualName].ToString();
                            ResultArray[this.DataColumns[3].ColumnIndex] = ResultRow[this.DataColumns[3].ActualName].ToString();
                            ResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[this.DataColumns[4].ActualName].ToString();
                            ResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[this.DataColumns[5].ActualName].ToString();
                            ResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[this.DataColumns[6].ActualName].ToString();
                            ResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[this.DataColumns[7].ActualName].ToString();
                            ResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[this.DataColumns[8].ActualName].ToString();
                            ResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[this.DataColumns[9].ActualName].ToString();
                            ResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[this.DataColumns[10].ActualName].ToString();
                            ResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[this.DataColumns[11].ActualName].ToString();
                            ResultArray[this.DataColumns[12].ColumnIndex] = (ResultRow[this.DataColumns[12].ActualName].ToString().Trim().Length > this.DataColumns[12].Size) ? ResultRow[this.DataColumns[12].ActualName].ToString().Trim().Substring(0, this.DataColumns[12].Size) : ResultRow[this.DataColumns[12].ActualName].ToString().Trim();
                            //if (ResultRow[this.DataColumns[12].ActualName].ToString().Trim().Length > 40)
                            //{
                            //    this.DataColumns[12].Size = 40;
                            //    //ResultArray[this.DataColumns[12].Size] = "40";
                            //    ResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[this.DataColumns[12].ActualName].ToString().Trim().Substring(0, 40);
                            //}
                            //else
                            //{
                            //    this.DataColumns[12].Size = ResultRow[this.DataColumns[12].ActualName].ToString().Trim().Length;
                            //    //ResultArray[this.DataColumns[12].Size] = ResultRow[this.DataColumns[12].ActualName].ToString().Trim().Length.ToString();
                            //    ResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[this.DataColumns[12].ActualName].ToString().Trim();
                            //}

                            //if (ResultList.Contains(ResultArray[this.DataColumns[3].ColumnIndex]))
                            //{
                            //    counter = ResultList.IndexOf(ResultArray);
                            //    double value = Convert.ToDouble(ResultTable.Rows[counter][this.DataColumns[7].ActualName]);
                            //    ResultArray[this.DataColumns[7].ColumnIndex] = Convert.ToString(Convert.ToDouble(ResultRow[this.DataColumns[7].ActualName]) + value);
                            //    ResultList.RemoveAt(counter);
                                
                            //}
                            if (counter > 0)
                            {
                                if (ResultRow[this.DataColumns[3].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[3].ActualName].ToString())==0 &&
                                    ResultRow[this.DataColumns[0].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[0].ActualName].ToString())==0 &&
                                    ResultRow[this.DataColumns[9].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[9].ActualName].ToString()) == 0 &&
                                    ResultRow[this.DataColumns[10].ActualName].ToString().CompareTo(ResultTable.Rows[counter -1][this.DataColumns[10].ActualName].ToString())==0 &&
                                    ResultRow[this.DataColumns[11].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[11].ActualName].ToString())==0)
                                {
                                    if (ResultRow[this.DataColumns[3].ActualName].ToString().CompareTo("120931") != 0 && ResultRow[this.DataColumns[3].ActualName].ToString().CompareTo("120199") != 0)
                                    {
                                        string[] TmpResultArray = (string[])ResultList[ResultList.Count - 1];

                                        decimal value = Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[7].ColumnIndex]), 2);
                                        decimal VAT = Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[8].ColumnIndex]), 2);
                                       // decimal value = Math.Round(Convert.ToDecimal(ResultTable.Rows[counter - 1][this.DataColumns[7].ActualName]),2);
                                        ResultArray[this.DataColumns[7].ColumnIndex] = Math.Round((Convert.ToDecimal(ResultRow[this.DataColumns[7].ActualName]) + value),2).ToString();
                                        ResultArray[this.DataColumns[8].ColumnIndex] = Math.Round((Convert.ToDecimal(ResultRow[this.DataColumns[8].ActualName]) + VAT), 2).ToString();
                                        ResultList.RemoveAt(ResultList.Count -1);
                                        //temp--;
                                    }
                                    //else
                                    //{
                                    //    ResultList.RemoveAt(ResultList.Count - 1);
                                    //    //temp--;
                                    //}
                                }
                            }

                            ResultList.Add(ResultArray);
                            counter++;
                            //temp++;

                        }

                    }
                    catch (Exception ex)
                    {
                        this.ErrMsg = ex.Message;
                    }
                }
                else
                {
                    this.ErrMsg = "[ClaimTransactionDataOutputManager.GenerateFileContent] : this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultList;
        }
        #endregion

        
    }
    #endregion

    #region CreditCardTransactionDataOutputManager
    public class CreditCardTransactionDataOutputManager : DataOutputManagerBase
    {
        public CreditCardTransactionDataOutputManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            // defined data column
            this.DataColumns.Add(new FileDataColumn(0, 10, "ECLAIM", "ECLAIM", true));
            this.DataColumns.Add(new FileDataColumn(1, 9, "EINVDT", "EINVDT", false));
            this.DataColumns.Add(new FileDataColumn(2, 1, "EPAYTY", "EPAYTY", true));
            this.DataColumns.Add(new FileDataColumn(3, 10, "EACC", "EACC", true));
            this.DataColumns.Add(new FileDataColumn(4, 6, "EEMPID", "EEMPID", true));
            this.DataColumns.Add(new FileDataColumn(5, 2, "ENTITY", "ENTITY", true));
            this.DataColumns.Add(new FileDataColumn(6, 3, "ECOMP", "ECOMP", false));
            this.DataColumns.Add(new FileDataColumn(7, 17, "ELAMT", "ELAMT", false));
            this.DataColumns.Add(new FileDataColumn(8, 17, "ELTAX", "ELTAX", false));
            this.DataColumns.Add(new FileDataColumn(9, 10, "EPRJID", "EPRJID", true));
            this.DataColumns.Add(new FileDataColumn(10, 10, "EPC", "EPC", true));
            this.DataColumns.Add(new FileDataColumn(11, 6, "EEMPCH", "EEMPCH", true));
            this.DataColumns.Add(new FileDataColumn(12, 50, "EDESC", "EDESC", true));
        }

        #region GenerateFileContent
        public override ArrayList GenerateFileContent(string Company)
        {
            ArrayList ResultList = null;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter("@CompanyID", Company));

                this.CurSQLFactory.ExecuteStoredProcedure("sp_FILEOUT_CreditCardTransaction", KeyParameters);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    // generate file now
                    ResultList = new ArrayList();

                    try
                    {
                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                            string[] ResultArray = new string[this.DataColumns.Count];
                            
                            ResultArray[this.DataColumns[0].ColumnIndex] = ResultRow[this.DataColumns[0].ActualName].ToString();
                            ResultArray[this.DataColumns[1].ColumnIndex] = "";
                            ResultArray[this.DataColumns[2].ColumnIndex] = ResultRow[this.DataColumns[2].ActualName].ToString();
                            ResultArray[this.DataColumns[3].ColumnIndex] = ResultRow[this.DataColumns[3].ActualName].ToString();
                            ResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[this.DataColumns[4].ActualName].ToString();
                            ResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[this.DataColumns[5].ActualName].ToString();
                            ResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[this.DataColumns[6].ActualName].ToString();
                            ResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[this.DataColumns[7].ActualName].ToString();
                            ResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[this.DataColumns[8].ActualName].ToString();
                            ResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[this.DataColumns[9].ActualName].ToString();
                            ResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[this.DataColumns[10].ActualName].ToString();
                            ResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[this.DataColumns[11].ActualName].ToString();
                            ResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[this.DataColumns[12].ActualName].ToString();

                            ResultList.Add(ResultArray);
                        }
                    }
                    catch (Exception ex)
                    {
                        this.ErrMsg = ex.Message;
                    }
                }
                else
                {
                    this.ErrMsg = "[CreditCardTransactionDataOutputManager.GenerateFileContent] : this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultList;
        }
        #endregion
    }
    #endregion

    #region ChinaAccrualReportDataOutputManager
    public class ChinaAccrualReportDataOutputManager : DataOutputManagerBase
    {
        public ChinaAccrualReportDataOutputManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {

            // defined data column
            this.DataColumns.Add(new FileDataColumn(0, 50, "EmployeeName", "EmployeeName", true));
            this.DataColumns.Add(new FileDataColumn(1, 6, "EmployeeID", "EmployeeID", true));
            this.DataColumns.Add(new FileDataColumn(2, 10, "ClaimID", "ClaimID", true));
            this.DataColumns.Add(new FileDataColumn(3, 10, "Period", "Period", true));
            this.DataColumns.Add(new FileDataColumn(4, 10, "80590", "80590", true));
            this.DataColumns.Add(new FileDataColumn(5, 10, "815340", "815340", true));
            this.DataColumns.Add(new FileDataColumn(6, 10, "815345", "815345", true));
            this.DataColumns.Add(new FileDataColumn(7, 10, "820110", "820110", true));
            this.DataColumns.Add(new FileDataColumn(8, 10, "820120", "820120", true));
            this.DataColumns.Add(new FileDataColumn(9, 10, "825320", "825320", true));
            this.DataColumns.Add(new FileDataColumn(10, 10, "830110", "830110", true));
            this.DataColumns.Add(new FileDataColumn(11, 10, "830130", "830130", true));
            this.DataColumns.Add(new FileDataColumn(12, 10, "830230", "830230", true));
            this.DataColumns.Add(new FileDataColumn(13, 10, "830250", "830250", true));
            this.DataColumns.Add(new FileDataColumn(14, 10, "865120", "865120", true));
            this.DataColumns.Add(new FileDataColumn(15, 10, "865130", "865130", true));
            this.DataColumns.Add(new FileDataColumn(16, 10, "865140", "865140", true));
            this.DataColumns.Add(new FileDataColumn(17, 10, "870110", "870110", true));
            this.DataColumns.Add(new FileDataColumn(18, 10, "870112", "870112", true));
            this.DataColumns.Add(new FileDataColumn(19, 10, "870114", "870114", true));
            this.DataColumns.Add(new FileDataColumn(20, 10, "870116", "870116", true));
            this.DataColumns.Add(new FileDataColumn(21, 10, "870120", "870120", true));
            this.DataColumns.Add(new FileDataColumn(22, 10, "870122", "870122", true));
            this.DataColumns.Add(new FileDataColumn(23, 10, "870124", "870124", true));
            this.DataColumns.Add(new FileDataColumn(24, 10, "870126", "870126", true));
            this.DataColumns.Add(new FileDataColumn(25, 10, "870128", "870128", true));
            this.DataColumns.Add(new FileDataColumn(26, 10, "870130", "870130", true));
            this.DataColumns.Add(new FileDataColumn(27, 10, "870140", "870140", true));
            this.DataColumns.Add(new FileDataColumn(28, 10, "870150", "870150", true));


        }

        #region GenerateFileContent
        public override ArrayList GenerateFileContent(string Company)
        {
            ArrayList ResultList = null;
            int counter = 0;
            int temp = 0;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter("@CompanyID", Company));


                this.CurSQLFactory.ExecuteStoredProcedure("sp_China_AccrualReport", KeyParameters);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    // generate file now
                    ResultList = new ArrayList();

                    try
                    {
                        string[] ResultArr = new string[this.DataColumns.Count];

                        ResultArr[this.DataColumns[0].ColumnIndex] = this.DataColumns[0].ActualName.ToString();
                        ResultArr[this.DataColumns[1].ColumnIndex] = this.DataColumns[1].ActualName.ToString();
                        ResultArr[this.DataColumns[2].ColumnIndex] = this.DataColumns[2].ActualName.ToString();
                        ResultArr[this.DataColumns[3].ColumnIndex] = this.DataColumns[3].ActualName.ToString();
                        ResultArr[this.DataColumns[4].ColumnIndex] = this.DataColumns[4].ActualName.ToString();
                        ResultArr[this.DataColumns[5].ColumnIndex] = this.DataColumns[5].ActualName.ToString();
                        ResultArr[this.DataColumns[6].ColumnIndex] = this.DataColumns[6].ActualName.ToString();
                        ResultArr[this.DataColumns[7].ColumnIndex] = this.DataColumns[7].ActualName.ToString();
                        ResultArr[this.DataColumns[8].ColumnIndex] = this.DataColumns[8].ActualName.ToString();
                        ResultArr[this.DataColumns[9].ColumnIndex] = this.DataColumns[9].ActualName.ToString();
                        ResultArr[this.DataColumns[10].ColumnIndex] = this.DataColumns[10].ActualName.ToString();
                        ResultArr[this.DataColumns[11].ColumnIndex] = this.DataColumns[11].ActualName.ToString();
                        ResultArr[this.DataColumns[12].ColumnIndex] = this.DataColumns[12].ActualName.ToString();
                        ResultArr[this.DataColumns[13].ColumnIndex] = this.DataColumns[13].ActualName.ToString();
                        ResultArr[this.DataColumns[14].ColumnIndex] = this.DataColumns[14].ActualName.ToString();
                        ResultArr[this.DataColumns[15].ColumnIndex] = this.DataColumns[15].ActualName.ToString();
                        ResultArr[this.DataColumns[16].ColumnIndex] = this.DataColumns[16].ActualName.ToString();
                        ResultArr[this.DataColumns[17].ColumnIndex] = this.DataColumns[17].ActualName.ToString();
                        ResultArr[this.DataColumns[18].ColumnIndex] = this.DataColumns[18].ActualName.ToString();
                        ResultArr[this.DataColumns[19].ColumnIndex] = this.DataColumns[19].ActualName.ToString();
                        ResultArr[this.DataColumns[20].ColumnIndex] = this.DataColumns[20].ActualName.ToString();
                        ResultArr[this.DataColumns[21].ColumnIndex] = this.DataColumns[21].ActualName.ToString();
                        ResultArr[this.DataColumns[22].ColumnIndex] = this.DataColumns[22].ActualName.ToString();
                        ResultArr[this.DataColumns[23].ColumnIndex] = this.DataColumns[23].ActualName.ToString();
                        ResultArr[this.DataColumns[24].ColumnIndex] = this.DataColumns[24].ActualName.ToString();
                        ResultArr[this.DataColumns[25].ColumnIndex] = this.DataColumns[25].ActualName.ToString();
                        ResultArr[this.DataColumns[26].ColumnIndex] = this.DataColumns[26].ActualName.ToString();
                        ResultArr[this.DataColumns[27].ColumnIndex] = this.DataColumns[27].ActualName.ToString();
                        ResultArr[this.DataColumns[28].ColumnIndex] = this.DataColumns[28].ActualName.ToString();

                        ResultList.Add(ResultArr);

                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                                string[] ResultArray = new string[this.DataColumns.Count];

                                //DateTime CurDate = DateTime.Parse(ResultRow[this.DataColumns[1].ActualName].ToString());

                                ResultArray[this.DataColumns[0].ColumnIndex] = ResultRow[0].ToString();
                                ResultArray[this.DataColumns[1].ColumnIndex] = ResultRow[1].ToString();
                                ResultArray[this.DataColumns[2].ColumnIndex] = ResultRow[2].ToString();
                                ResultArray[this.DataColumns[3].ColumnIndex] = ResultRow[3].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[4].ActualName) == 0)
                                    ResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[5].ActualName) == 0)
                                    ResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[6].ActualName) == 0)
                                    ResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[7].ActualName) == 0)
                                    ResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[8].ActualName) == 0)
                                    ResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[9].ActualName) == 0)
                                    ResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[10].ActualName) == 0)
                                    ResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                    ResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[12].ActualName) == 0)
                                    ResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[13].ActualName) == 0)
                                    ResultArray[this.DataColumns[13].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[14].ActualName) == 0)
                                    ResultArray[this.DataColumns[14].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[15].ActualName) == 0)
                                    ResultArray[this.DataColumns[15].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[16].ActualName) == 0)
                                    ResultArray[this.DataColumns[16].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[17].ActualName) == 0)
                                    ResultArray[this.DataColumns[17].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[18].ActualName) == 0)
                                    ResultArray[this.DataColumns[18].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[19].ActualName) == 0)
                                    ResultArray[this.DataColumns[19].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[20].ActualName) == 0)
                                    ResultArray[this.DataColumns[20].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[21].ActualName) == 0)
                                    ResultArray[this.DataColumns[21].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[22].ActualName) == 0)
                                    ResultArray[this.DataColumns[22].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[23].ActualName) == 0)
                                    ResultArray[this.DataColumns[23].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[24].ActualName) == 0)
                                    ResultArray[this.DataColumns[24].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[25].ActualName) == 0)
                                    ResultArray[this.DataColumns[25].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[26].ActualName) == 0)
                                    ResultArray[this.DataColumns[26].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[27].ActualName) == 0)
                                    ResultArray[this.DataColumns[27].ColumnIndex] = ResultRow[5].ToString();
                                if (ResultRow[4].ToString().CompareTo(this.DataColumns[28].ActualName) == 0)
                                    ResultArray[this.DataColumns[28].ColumnIndex] = ResultRow[5].ToString();

                                if (counter > 0)
                                {
                                    if (ResultRow[this.DataColumns[1].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[1].ActualName].ToString()) == 0 &&
                                        ResultRow[this.DataColumns[2].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[2].ActualName].ToString()) == 0)
                                    {

                                        string[] TmpResultArray = (string[])ResultList[ResultList.Count - 1];

                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[4].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[5].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[6].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[7].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[8].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[9].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[10].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[12].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[13].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[13].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[14].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[14].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[15].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[15].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[16].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[16].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[17].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[17].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[18].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[18].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[19].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[19].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[20].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[20].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[21].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[21].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[22].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[22].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[23].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[23].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[24].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[24].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[25].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[25].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[26].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[26].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[27].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[27].ColumnIndex] = ResultRow[5].ToString();
                                        if (ResultRow[4].ToString().CompareTo(this.DataColumns[28].ActualName) == 0)
                                            TmpResultArray[this.DataColumns[28].ColumnIndex] = ResultRow[5].ToString();
                                        ResultList.RemoveAt(ResultList.Count - 1);
                                        //ResultArray = TmpResultArray;
                                        ResultList.Add(TmpResultArray);
                                        counter++;
                                        //temp--;

                                    }
                                    else
                                    {
                                        ResultList.Add(ResultArray);
                                        counter++;
                                    }

                                }
                                else
                                {
                                    ResultList.Add(ResultArray);
                                    counter++;
                                }
                        }

                    }
                    catch (Exception ex)
                    {
                        this.ErrMsg = ex.Message;
                    }
                }
                else
                {
                    this.ErrMsg = "[ChinaAccrualReportDataOutputManager.GenerateFileContent] : this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultList;
        }
        #endregion


    }
    #endregion

    #region ChinaTnEExpenseReportDataOutputManager
    public class ChinaTnEExpenseReportDataOutputManager : DataOutputManagerBase
    {
        public ChinaTnEExpenseReportDataOutputManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {

            // defined data column
            this.DataColumns.Add(new FileDataColumn(0, 50, "EmployeeName", "EmployeeName", true));
            this.DataColumns.Add(new FileDataColumn(1, 6, "EmployeeID", "EmployeeID", true));
            this.DataColumns.Add(new FileDataColumn(2, 10, "Period", "Period", true));
            this.DataColumns.Add(new FileDataColumn(3, 10, "80590", "80590", true));
            this.DataColumns.Add(new FileDataColumn(4, 10, "815340", "815340", true));
            this.DataColumns.Add(new FileDataColumn(5, 10, "815345", "815345", true));
            this.DataColumns.Add(new FileDataColumn(6, 10, "820110", "820110", true));
            this.DataColumns.Add(new FileDataColumn(7, 10, "820120", "820120", true));
            this.DataColumns.Add(new FileDataColumn(8, 10, "825320", "825320", true));
            this.DataColumns.Add(new FileDataColumn(9, 10, "830110", "830110", true));
            this.DataColumns.Add(new FileDataColumn(10, 10, "830130", "830130", true));
            this.DataColumns.Add(new FileDataColumn(11, 10, "830230", "830230", true));
            this.DataColumns.Add(new FileDataColumn(12, 10, "830250", "830250", true));
            this.DataColumns.Add(new FileDataColumn(13, 10, "865120", "865120", true));
            this.DataColumns.Add(new FileDataColumn(14, 10, "865130", "865130", true));
            this.DataColumns.Add(new FileDataColumn(15, 10, "865140", "865140", true));
            this.DataColumns.Add(new FileDataColumn(16, 10, "870110", "870110", true));
            this.DataColumns.Add(new FileDataColumn(17, 10, "870112", "870112", true));
            this.DataColumns.Add(new FileDataColumn(18, 10, "870114", "870114", true));
            this.DataColumns.Add(new FileDataColumn(19, 10, "870116", "870116", true));
            this.DataColumns.Add(new FileDataColumn(20, 10, "870120", "870120", true));
            this.DataColumns.Add(new FileDataColumn(21, 10, "870122", "870122", true));
            this.DataColumns.Add(new FileDataColumn(22, 10, "870124", "870124", true));
            this.DataColumns.Add(new FileDataColumn(23, 10, "870126", "870126", true));
            this.DataColumns.Add(new FileDataColumn(24, 10, "870128", "870128", true));
            this.DataColumns.Add(new FileDataColumn(25, 10, "870130", "870130", true));
            this.DataColumns.Add(new FileDataColumn(26, 10, "870140", "870140", true));
            this.DataColumns.Add(new FileDataColumn(27, 10, "870150", "870150", true));


        }

        #region GenerateFileContent
        public override ArrayList GenerateFileContent(string Company)
        {
            ArrayList ResultList = null;
            int counter = 0;
            int temp = 0;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter("@CompanyID", Company));


                this.CurSQLFactory.ExecuteStoredProcedure("sp_China_TnEExpenseReport", KeyParameters);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    // generate file now
                    ResultList = new ArrayList();

                    try
                    {
                        string[] ResultArr = new string[this.DataColumns.Count];

                        ResultArr[this.DataColumns[0].ColumnIndex] = this.DataColumns[0].ActualName.ToString();
                        ResultArr[this.DataColumns[1].ColumnIndex] = this.DataColumns[1].ActualName.ToString();
                        ResultArr[this.DataColumns[2].ColumnIndex] = this.DataColumns[2].ActualName.ToString();
                        ResultArr[this.DataColumns[3].ColumnIndex] = this.DataColumns[3].ActualName.ToString();
                        ResultArr[this.DataColumns[4].ColumnIndex] = this.DataColumns[4].ActualName.ToString();
                        ResultArr[this.DataColumns[5].ColumnIndex] = this.DataColumns[5].ActualName.ToString();
                        ResultArr[this.DataColumns[6].ColumnIndex] = this.DataColumns[6].ActualName.ToString();
                        ResultArr[this.DataColumns[7].ColumnIndex] = this.DataColumns[7].ActualName.ToString();
                        ResultArr[this.DataColumns[8].ColumnIndex] = this.DataColumns[8].ActualName.ToString();
                        ResultArr[this.DataColumns[9].ColumnIndex] = this.DataColumns[9].ActualName.ToString();
                        ResultArr[this.DataColumns[10].ColumnIndex] = this.DataColumns[10].ActualName.ToString();
                        ResultArr[this.DataColumns[11].ColumnIndex] = this.DataColumns[11].ActualName.ToString();
                        ResultArr[this.DataColumns[12].ColumnIndex] = this.DataColumns[12].ActualName.ToString();
                        ResultArr[this.DataColumns[13].ColumnIndex] = this.DataColumns[13].ActualName.ToString();
                        ResultArr[this.DataColumns[14].ColumnIndex] = this.DataColumns[14].ActualName.ToString();
                        ResultArr[this.DataColumns[15].ColumnIndex] = this.DataColumns[15].ActualName.ToString();
                        ResultArr[this.DataColumns[16].ColumnIndex] = this.DataColumns[16].ActualName.ToString();
                        ResultArr[this.DataColumns[17].ColumnIndex] = this.DataColumns[17].ActualName.ToString();
                        ResultArr[this.DataColumns[18].ColumnIndex] = this.DataColumns[18].ActualName.ToString();
                        ResultArr[this.DataColumns[19].ColumnIndex] = this.DataColumns[19].ActualName.ToString();
                        ResultArr[this.DataColumns[20].ColumnIndex] = this.DataColumns[20].ActualName.ToString();
                        ResultArr[this.DataColumns[21].ColumnIndex] = this.DataColumns[21].ActualName.ToString();
                        ResultArr[this.DataColumns[22].ColumnIndex] = this.DataColumns[22].ActualName.ToString();
                        ResultArr[this.DataColumns[23].ColumnIndex] = this.DataColumns[23].ActualName.ToString();
                        ResultArr[this.DataColumns[24].ColumnIndex] = this.DataColumns[24].ActualName.ToString();
                        ResultArr[this.DataColumns[25].ColumnIndex] = this.DataColumns[25].ActualName.ToString();
                        ResultArr[this.DataColumns[26].ColumnIndex] = this.DataColumns[26].ActualName.ToString();
                        ResultArr[this.DataColumns[27].ColumnIndex] = this.DataColumns[27].ActualName.ToString();

                        ResultList.Add(ResultArr);

                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                            string[] ResultArray = new string[this.DataColumns.Count];

                            //DateTime CurDate = DateTime.Parse(ResultRow[this.DataColumns[1].ActualName].ToString());

                            ResultArray[this.DataColumns[0].ColumnIndex] = ResultRow[0].ToString();
                            ResultArray[this.DataColumns[1].ColumnIndex] = ResultRow[1].ToString();
                            ResultArray[this.DataColumns[2].ColumnIndex] = ResultRow[2].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[3].ActualName) == 0)
                                ResultArray[this.DataColumns[3].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[4].ActualName) == 0)
                                ResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[5].ActualName) == 0)
                                ResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[6].ActualName) == 0)
                                ResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[7].ActualName) == 0)
                                ResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[8].ActualName) == 0)
                                ResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[9].ActualName) == 0)
                                ResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[10].ActualName) == 0)
                                ResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                ResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[12].ActualName) == 0)
                                ResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[13].ActualName) == 0)
                                ResultArray[this.DataColumns[13].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[14].ActualName) == 0)
                                ResultArray[this.DataColumns[14].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[15].ActualName) == 0)
                                ResultArray[this.DataColumns[15].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[16].ActualName) == 0)
                                ResultArray[this.DataColumns[16].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[17].ActualName) == 0)
                                ResultArray[this.DataColumns[17].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[18].ActualName) == 0)
                                ResultArray[this.DataColumns[18].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[19].ActualName) == 0)
                                ResultArray[this.DataColumns[19].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[20].ActualName) == 0)
                                ResultArray[this.DataColumns[20].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[21].ActualName) == 0)
                                ResultArray[this.DataColumns[21].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[22].ActualName) == 0)
                                ResultArray[this.DataColumns[22].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[23].ActualName) == 0)
                                ResultArray[this.DataColumns[23].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[24].ActualName) == 0)
                                ResultArray[this.DataColumns[24].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[25].ActualName) == 0)
                                ResultArray[this.DataColumns[25].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[26].ActualName) == 0)
                                ResultArray[this.DataColumns[26].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[27].ActualName) == 0)
                                ResultArray[this.DataColumns[27].ColumnIndex] = ResultRow[4].ToString();

                            if (counter > 0)
                            {
                                if (ResultRow[this.DataColumns[1].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[1].ActualName].ToString()) == 0)
                                {

                                    string[] TmpResultArray = (string[])ResultList[ResultList.Count - 1];

                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[3].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[3].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[3].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]), 2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[4].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[4].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[4].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[5].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[5].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[5].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]), 2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[6].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[6].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[6].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]), 2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[7].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[7].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[7].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]), 2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[8].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[8].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[8].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[9].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[9].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[9].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[11].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[10].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[11].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[11].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[12].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[12].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[12].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[13].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[13].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[13].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[14].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[14].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[14].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[15].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[15].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[15].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[16].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[16].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[16].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[17].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[17].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[17].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[18].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[18].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[18].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[19].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[19].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[19].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[20].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[20].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[20].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[21].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[21].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[21].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[22].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[22].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[22].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[23].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[23].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[23].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[24].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[24].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[24].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[25].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[25].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[25].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[26].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[26].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[26].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[27].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[27].ColumnIndex] = (Math.Round(Convert.ToDecimal(TmpResultArray[this.DataColumns[27].ColumnIndex]), 2) + Math.Round(Convert.ToDecimal(ResultRow[4]),2)).ToString();
                                    ResultList.RemoveAt(ResultList.Count - 1);
                                    //ResultArray = TmpResultArray;
                                    ResultList.Add(TmpResultArray);
                                    counter++;
                                    //temp--;

                                }
                                else
                                {
                                    ResultList.Add(ResultArray);
                                    counter++;
                                }

                            }
                            else
                            {
                                ResultList.Add(ResultArray);
                                counter++;
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        this.ErrMsg = ex.Message;
                    }
                }
                else
                {
                    this.ErrMsg = "[ChinaTnEExpenseReportDataOutputManager.GenerateFileContent] : this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultList;
        }
        #endregion


    }
    #endregion

    #region ChinaTnEExpenseFINReportDataOutputManager
    public class ChinaTnEExpenseFINReportDataOutputManager : DataOutputManagerBase
    {
        public ChinaTnEExpenseFINReportDataOutputManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {

            // defined data column
            this.DataColumns.Add(new FileDataColumn(0, 50, "ProfitCenter", "ProfitCenter", true));
            this.DataColumns.Add(new FileDataColumn(1, 6, "EmployeeID", "EmployeeID", true));
            this.DataColumns.Add(new FileDataColumn(2, 10, "EmployeeName", "EmployeeName", true));
            this.DataColumns.Add(new FileDataColumn(3, 10, "Jan", "Jan", true));
            this.DataColumns.Add(new FileDataColumn(4, 10, "Feb", "Feb", true));
            this.DataColumns.Add(new FileDataColumn(5, 10, "Mar", "Mar", true));
            this.DataColumns.Add(new FileDataColumn(6, 10, "Apr", "Apr", true));
            this.DataColumns.Add(new FileDataColumn(7, 10, "May", "May", true));
            this.DataColumns.Add(new FileDataColumn(8, 10, "Jun", "Jun", true));
            this.DataColumns.Add(new FileDataColumn(9, 10, "Jul", "Jul", true));
            this.DataColumns.Add(new FileDataColumn(10, 10, "Aug", "Aug", true));
            this.DataColumns.Add(new FileDataColumn(11, 10, "Sep", "Sep", true));
            this.DataColumns.Add(new FileDataColumn(12, 10, "Oct", "Oct", true));
            this.DataColumns.Add(new FileDataColumn(13, 10, "Nov", "Nov", true));
            this.DataColumns.Add(new FileDataColumn(14, 10, "Dec", "Dec", true));


        }

        #region GenerateFileContent
        public override ArrayList GenerateFileContent(string Company)
        {
            ArrayList ResultList = null;
            int counter = 0;
            int temp = 0;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter("@CompanyID", Company));


                this.CurSQLFactory.ExecuteStoredProcedure("sp_China_TnEExpenseFINReport", KeyParameters);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    // generate file now
                    ResultList = new ArrayList();

                    try
                    {
                        string[] ResultArr = new string[this.DataColumns.Count];

                        ResultArr[this.DataColumns[0].ColumnIndex] = this.DataColumns[0].ActualName.ToString();
                        ResultArr[this.DataColumns[1].ColumnIndex] = this.DataColumns[1].ActualName.ToString();
                        ResultArr[this.DataColumns[2].ColumnIndex] = this.DataColumns[2].ActualName.ToString();
                        ResultArr[this.DataColumns[3].ColumnIndex] = this.DataColumns[3].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[4].ColumnIndex] = this.DataColumns[4].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[5].ColumnIndex] = this.DataColumns[5].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[6].ColumnIndex] = this.DataColumns[6].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[7].ColumnIndex] = this.DataColumns[7].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[8].ColumnIndex] = this.DataColumns[8].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[9].ColumnIndex] = this.DataColumns[9].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[10].ColumnIndex] = this.DataColumns[10].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[11].ColumnIndex] = this.DataColumns[11].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[12].ColumnIndex] = this.DataColumns[12].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[13].ColumnIndex] = this.DataColumns[13].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                        ResultArr[this.DataColumns[14].ColumnIndex] = this.DataColumns[14].ActualName.ToString() + "." + DateTime.Now.Year.ToString();
                       
                        ResultList.Add(ResultArr);

                        foreach (DataRow ResultRow in ResultTable.Rows)
                        {
                            string[] ResultArray = new string[this.DataColumns.Count];

                            //DateTime CurDate = DateTime.Parse(ResultRow[this.DataColumns[1].ActualName].ToString());

                            ResultArray[this.DataColumns[0].ColumnIndex] = ResultRow[0].ToString();
                            ResultArray[this.DataColumns[1].ColumnIndex] = ResultRow[1].ToString();
                            ResultArray[this.DataColumns[2].ColumnIndex] = ResultRow[2].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[3].ActualName) == 0)
                                ResultArray[this.DataColumns[3].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[4].ActualName) == 0)
                                ResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[5].ActualName) == 0)
                                ResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[6].ActualName) == 0)
                                ResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[7].ActualName) == 0)
                                ResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[8].ActualName) == 0)
                                ResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[9].ActualName) == 0)
                                ResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[10].ActualName) == 0)
                                ResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                ResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[12].ActualName) == 0)
                                ResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[13].ActualName) == 0)
                                ResultArray[this.DataColumns[13].ColumnIndex] = ResultRow[4].ToString();
                            if (ResultRow[3].ToString().CompareTo(this.DataColumns[14].ActualName) == 0)
                                ResultArray[this.DataColumns[14].ColumnIndex] = ResultRow[4].ToString();
                 

                            if (counter > 0)
                            {
                                if (ResultRow[this.DataColumns[1].ActualName].ToString().CompareTo(ResultTable.Rows[counter - 1][this.DataColumns[1].ActualName].ToString()) == 0)
                                {

                                    string[] TmpResultArray = (string[])ResultList[ResultList.Count - 1];

                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[3].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[3].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[4].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[4].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[5].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[5].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[6].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[6].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[7].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[7].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[8].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[8].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[9].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[9].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[10].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[10].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[11].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[11].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[12].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[12].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[13].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[13].ColumnIndex] = ResultRow[4].ToString();
                                    if (ResultRow[3].ToString().CompareTo(this.DataColumns[14].ActualName) == 0)
                                        TmpResultArray[this.DataColumns[14].ColumnIndex] = ResultRow[4].ToString();

                                    ResultList.RemoveAt(ResultList.Count - 1);
                                    //ResultArray = TmpResultArray;
                                    ResultList.Add(TmpResultArray);
                                    counter++;
                                    //temp--;

                                }
                                else
                                {
                                    ResultList.Add(ResultArray);
                                    counter++;
                                }

                            }
                            else
                            {
                                ResultList.Add(ResultArray);
                                counter++;
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        this.ErrMsg = ex.Message;
                    }
                }
                else
                {
                    this.ErrMsg = "[ChinaTnEExpenseFINReportDataOutputManager.GenerateFileContent] : this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultList;
        }
        #endregion


    }
    #endregion

}
